//
//  MoneyStateCell.m
//  MyNewProject
//
//  Created by sun on 2019/1/28.
//  Copyright © 2019 sun. All rights reserved.
//

#import "MoneyStateCell.h"
@interface MoneyStateCell()

@property(nonatomic,strong)UIButton * amountBtn;

@property(nonatomic,strong)UIButton * detailBtn;
@property(nonatomic,copy)UILabel * amountLab;


@end
@implementation MoneyStateCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initView];
        
    }
    return self;
    
    
}
-(void)initView
{
    
    
    [self.contentView addSubview:self.amountBtn];
    
//    [self.contentView addSubview:self.amountLab];
    
    [self.contentView addSubview:self.detailBtn];
    
    CGFloat leftAndRight = 0;
    
    CGFloat labelWidth =(SCREEN_WIDTH - leftAndRight)/4.0;
    NSArray * bottomNameArr = @[@"账户余额",@"冻结保证金",@"可用余额",@"可取金额"];

    for (int i = 0; i <4 ; i++) {
       
        UILabel * topLab =[[UILabel alloc] initWithFrame:CGRectMake(leftAndRight + labelWidth *i, self.amountBtn.bottom +10 , labelWidth, 20)];
        
        topLab.textAlignment = NSTextAlignmentCenter;
        
        topLab.textColor= SKColorWithHex(0x444444);
        
        topLab.font = SKFONT_Medium(14);
        
        topLab.tag = 10000000 + i;
//        topLab.text =@"0.00";
        [self.contentView addSubview:topLab];
        
        if (i<3) {
            
            UIImageView * imageView =[[UIImageView alloc] initWithFrame:CGRectMake(topLab.right, topLab.top +5, 0.5, 40)];
            imageView.backgroundColor =[UIColor lightGrayColor];
            
            [self.contentView addSubview:imageView];
            
        }
        UILabel * bottomLab =[[UILabel alloc] initWithFrame:CGRectMake(leftAndRight + labelWidth *i, topLab.bottom +10, labelWidth, 20)];
        
        bottomLab.textAlignment = NSTextAlignmentCenter;
        bottomLab.textColor= SKColorWithHex(0x999999);

        bottomLab.font = SKFONT_Medium(11);
        bottomLab.tag = 20000000 +i;

        bottomLab.text =bottomNameArr[i];
        [self.contentView addSubview:bottomLab];
        
    }
    
//    UIImageView * imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, self.amountBtn.bottom+10+50+10, SCREEN_WIDTH, 0.5)];
//    imageView.backgroundColor =[UIColor lightGrayColor];
//
//    [self.contentView addSubview:imageView];
    
    
    CGFloat leftAndRightBtn = 30;
    
    CGFloat btnWidth =80;
    
    NSArray * nameArr = @[@"提 现",@"充 值"];
    for (int i = 0; i<nameArr.count; i++) {
        NSString * totalAmtStr = nameArr[i];
        UIFont * font = SKFONT_Medium(14);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        button.frame = CGRectMake(SCREEN_WIDTH/2 + leftAndRightBtn *(-1 +2*i) + btnWidth*(-1 +i), self.amountBtn.bottom+10+50+15, btnWidth , 22);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        
        button.tag = 100000000 + i;
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
   
        if (i == 0) {
//            button.backgroundColor = [UIColor clearColor];

            button.layer.borderColor = SKRGBColor(52, 52, 52).CGColor;
            button.layer.borderWidth = 0.5;
            [button setTitleColor:SKColorWithHex(0x444444) forState:UIControlStateNormal];

        }
        else
        {
            button.backgroundColor = SKColorWithHex(0x7ab801);
            [button setTitleColor:SKColorWithHex(0xFFFEFE) forState:UIControlStateNormal];
            
        }
        button.layer.cornerRadius = button.height/2;
        button.layer.masksToBounds = YES;
        
        
        [button addTarget:self action:@selector(eventDeal:) forControlEvents:UIControlEventTouchUpInside];

        [self.contentView  addSubview:button];
        
    }
    
}
-(void)eventDeal:(UIButton *)sender
{
    long count = sender.tag -100000000;
    
    NSLog(@"%ld",count);
    
    if (self.myEventBlock) {
        
        self.myEventBlock(@"", count);

    }
    
    
}
-(UIButton*)amountBtn
{
    if (_amountBtn ==nil) {
        NSString * totalAmtStr = [NSString stringWithFormat:@"累计收益总金额:%.2lf",[UserInfoSingleton shareInstance].userInfo.keyong_yue.doubleValue];
        UIFont * font = SKFONT_Medium(14);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        CGFloat strWidth = [NSString getWidthWithString:totalAmtStr font:font lineBreakModel:NSLineBreakByCharWrapping];
        
        button.frame = CGRectMake(10, 0, strWidth + 10+5 , 40);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        button.backgroundColor = [UIColor clearColor];
        
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
        [button setTitleColor:SKColorWithHex(0x444444) forState:UIControlStateNormal];
        
//        [button setImage:[self createImageWithColor:[UIColor redColor] withRect:CGSizeMake(10, 10)] forState:UIControlStateNormal];
//        [button setImagePosition:LXMImagePositionLeft spacing:5];
        

        _amountBtn = button;
    }
    
    return _amountBtn;
    
}
-(UILabel*)amountLab
{
    if (_amountLab == nil) {
        UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(self.amountBtn.right, self.amountBtn.top, 60, self.amountBtn.height)];
        label.numberOfLines = 1 ;
        label.textAlignment = NSTextAlignmentLeft;
        
        
        label.font = self.amountBtn.titleLabel.font;
        
        label.textColor = [UIColor redColor];
        
        label.text = @"0.00";
        _amountLab = label;
        
    }
    return _amountLab;
 
}

-(UIButton*)detailBtn
{
    if (_detailBtn ==nil) {
        NSString * totalAmtStr = @"明细";
        UIFont * font = SKFONT_Medium(14);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        CGFloat strWidth = [NSString getWidthWithString:totalAmtStr font:font lineBreakModel:NSLineBreakByCharWrapping];
        
        button.frame = CGRectMake(SCREEN_WIDTH -(strWidth + 15+5) - 15, 0, strWidth + 15+5 , 40);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        button.backgroundColor = [UIColor clearColor];
        
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
        [button setTitleColor:SKRGBColor(128, 128, 128) forState:UIControlStateNormal];
        
        [button setImage:SKIMAGE_NAMED(@"rightArrow") forState:UIControlStateNormal];
        [button setImagePosition:LXMImagePositionRight spacing:5];
        
        [button addTarget:self action:@selector(lookDetail:) forControlEvents:UIControlEventTouchUpInside];
        
        _detailBtn = button;
    }
    
    return _detailBtn;
    
}
#pragma mark -- 查看明细
-(void)lookDetail:(UIButton*)sender
{
    
    if (self.myDetailBlock) {
        
        self.myDetailBlock(@"");
    }
}

-(void)setModel:(id)model
{
    NSString * totalAmtStr = [NSString stringWithFormat:@"累计收益总金额:%.2lf",[[UserInfoSingleton shareInstance].userInfo.income floatValue]];

    [self.amountBtn setTitle:totalAmtStr forState:UIControlStateNormal];
    UILabel * label = [self.contentView viewWithTag:10000000];
    label.text = [NSString stringWithFormat:@"%.2lf",[[UserInfoSingleton shareInstance].userInfo.yue floatValue]];
    
    UILabel * label1 = [self.contentView viewWithTag:10000001];
    label1.text = [NSString stringWithFormat:@"%.2lf",[[UserInfoSingleton shareInstance].userInfo.bail floatValue]];
    
    
    UILabel * label2 = [self.contentView viewWithTag:10000002];
    label2.text = [NSString stringWithFormat:@"%.2lf",[UserInfoSingleton shareInstance].userInfo.keyong_yue.doubleValue];
    
    UILabel * label3 = [self.contentView viewWithTag:10000003];
    label3.text = [NSString stringWithFormat:@"%.2lf",[UserInfoSingleton shareInstance].userInfo.keyong_yue.doubleValue];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
